<?php
namespace app\app\model;
use think\Db;
use think\Model;

class HistoryModel extends Model{

    public $user_id;
    protected $table = "a_history";

    /**
     * 获取卡片
     * @param $id
     * @return array|false|\PDOStatement|string|Model
     * @throws \think\exception\DbException
     */
    public function getOne($id){
        $data = $this->field('name,concat("'.getConfig('IMG_HEAD').'",img) img')->where('id','eq',$id)->find();
        $history = Db::name('user_history')->where('user_id','eq',$this->user_id)->where('h_id','eq',$id)->find();
        if( $history ){
            Db::query('update a_user_history set num = num + 1 where id='.$history['id']);
        }else{
            Db::name('user_history')->insert(array('user_id'=>$this->user_id,'h_id'=>$id,'num'=>1));
        }
        return $data;
    }

}